<template>
	<div>
		<u-sticky>
			<div class="searchBox">
				<u-search placeholder="输入姓名搜索" v-model="searchName"></u-search>
			</div>
		</u-sticky>
		<view class="bg_container">
			<div class="userlist" v-if="xblss">
				<div class="item" v-for="(item,index) in searchResult" @click="changeDetail(item)">
					<h3>{{ item }}</h3>
				</div>
			</div>
		</view>
	</div>
</template>

<script>
	const db = wx.cloud.database()
	export default {
		name: 'headcomd',
		data() {
			return {
				searchName:"",
				xblss:[]
			};
		},
		onShareAppMessage(options) {},
		onLoad(options) {
			
		},
		computed: {
			searchResult(){
				let that = this
				let arr = []
				if(that.searchName){
					arr = that.xblss.filter(item => item.indexOf(that.searchName) != -1)
				}else{
					arr = that.xblss
				}
				return arr
			}
		},
		mounted() {
			this.getList()
		},
		watch: {

		},
		created() {
			let that = this;

		},
		methods: {
			async getList(){
				let that = this
				const $ = db.command.aggregate
				let list = await db.collection('24gk_students')
					.aggregate()
					.group({
					  //不指定id字段是为了下面分组查找
					  _id: null,
					  //categories是设置的字段，addToSet是添加字段，$name是获取数据库中的name字段数据
					  xbls: $.addToSet('$xbls')
					})
					.end()
					console.log(list.list,'list.list')
				that.xblss = list.list[0].xbls
			},
			changeDetail(name){
				uni.navigateTo({
					url:'./detailList?xbls=' + name
				})
			}
		}
	};
</script>

<style>
	@import url("./index.css");
</style>